﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HFK.DxFluentUITest.Dummy.DataObjects;
using HFK.DxFluentUI.Utility;
using MbUnit.Framework;

namespace HFK.DxFluentUITest.Utility
{
  [TestFixture]
  public class ReflectionHelperTestFixture
  {
    [Test]
    public void TestZeroHopReflection()
    {
      const int intTestValue = 1;
      const string stringTestValue = "string1";

      SimpleClass simpleClass = new SimpleClass();
      simpleClass.IntValue = intTestValue;
      simpleClass.StringValue = stringTestValue;

      object intObject = ReflectionHelper.GetPropertyValue(simpleClass, "IntValue");
      object stringObject = ReflectionHelper.GetPropertyValue(simpleClass, "StringValue");

      Assert.IsInstanceOfType(typeof(int), intObject);
      Assert.AreEqual(intTestValue, (int)intObject);
      Assert.IsInstanceOfType(typeof(string), stringObject);
      Assert.AreEqual(stringTestValue, (string)stringObject);
    }

    [Test]
    public void TestSingleHopReflection()
    {
      const int intTestValue = 1;
      const string stringTestValue = "string1";

      SimpleClass simpleClass = new SimpleClass();
      simpleClass.IntValue = intTestValue;
      simpleClass.ShcData = new SingleHopClass() { StringValue = stringTestValue };

      object intObject = ReflectionHelper.GetPropertyValue(simpleClass, "IntValue");
      object stringObject = ReflectionHelper.GetPropertyValue(simpleClass, "ShcData.StringValue");

      Assert.IsInstanceOfType(typeof(int), intObject);
      Assert.AreEqual(intTestValue, (int)intObject);
      Assert.IsInstanceOfType(typeof(string), stringObject);
      Assert.AreEqual(stringTestValue, (string)stringObject);
    }

    [Test]
    public void TestTripleHopReflection()
    {
      const int intTestValue = 1;
      const string stringTestValue = "string1";

      SimpleClass simpleClass = new SimpleClass();
      simpleClass.IntValue = intTestValue;
      simpleClass.ShcData = new SingleHopClass()
      {
        StringValue = stringTestValue,
        DhcProperty = new DualHopClass()
        {
          ThcProperty = new TripleHopClass()
          {
            StringProperty = stringTestValue
          }
        }
      };

      object intObject = ReflectionHelper.GetPropertyValue(simpleClass, "IntValue");
      object stringObject = ReflectionHelper.GetPropertyValue(simpleClass, "ShcData.DhcProperty.ThcProperty.StringProperty");

      Assert.IsInstanceOfType(typeof(int), intObject);
      Assert.AreEqual(intTestValue, (int)intObject);
      Assert.IsInstanceOfType(typeof(string), stringObject);
      Assert.AreEqual(stringTestValue, (string)stringObject);
    }
  }
}
